//
//  ActivityListTableViewCell.m
//  UI_TabBarTest1(豆瓣)
//
//  Created by dllo on 16/6/23.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "ActivityListTableViewCell.h"
#import "Activity.h"
@interface ActivityListTableViewCell ()

@property (nonatomic,retain)UILabel *titleLabel;   /** 标题label */
//@property (nonatomic,retain)UIImageView *timeImageView;
@property (nonatomic,retain)UILabel *timeLabel;     /** 时间label */
//@property (nonatomic,retain)UIImageView *addressImageView;
@property (nonatomic,retain)UILabel *addressLabel;      /** 地址label */

@property (nonatomic,retain)UILabel *category_nameLabel;    /** 类型label */

@property (nonatomic,retain)UILabel *wisher_countLabel;     /** 感兴趣label */

@property (nonatomic,retain)UILabel *participant_countLabel;     /** 参加label */

@property (nonatomic,retain)UIImageView *activityListImageView;     /** 图片的imageView */

/** 固定内容的imageView或者Label */

/** 底层图片 */
@property (nonatomic,retain)UIImageView *backGroundImageViewBottom;

@property (nonatomic,retain)UIImageView *backGroundImageViewMid;

@property (nonatomic,retain)UIImageView *timeImageView;

@property (nonatomic,retain)UIImageView *addressImageView;

@property (nonatomic,retain)UIImageView *categoryImageView;

@property (nonatomic,retain)UILabel *categoryLabel;

@property (nonatomic,retain)UILabel *wisherLabel;

@property (nonatomic,retain)UILabel *participant;

@end

@implementation ActivityListTableViewCell

-(void)dealloc{
    [_titleLabel release];
    [_timeLabel release];
    [_addressLabel release];
    [_category_nameLabel release];
    [_wisher_countLabel release];
    [_participant_countLabel release];
    [_activityListImageView release];
    [_activity release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        
        /** 固定内容imageView或者Label */
/**1*/        self.backGroundImageViewBottom = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_eventlistcell"]];
        [self.contentView addSubview:self.backGroundImageViewBottom];
        
        self.backGroundImageViewMid = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_share_large"]];
        [self.backGroundImageViewBottom addSubview:self.backGroundImageViewMid];
        
        self.timeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_date"]];
        [self.backGroundImageViewMid addSubview:self.timeImageView];
        
        self.addressImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_spot"]];
        [self.backGroundImageViewMid addSubview:self.addressImageView];
        
        self.categoryImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_catalog"]];
        [self.backGroundImageViewMid addSubview:self.categoryImageView];
        
        self.categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 65, 40, 25)];
        [self.backGroundImageViewMid addSubview:self.categoryLabel];
        
        self.wisherLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 105, 50, 30)];
        [self.backGroundImageViewMid addSubview:self.wisherLabel];
        
        self.participant = [[UILabel alloc] initWithFrame:CGRectMake(140, 105, 50, 30)];
        [self.backGroundImageViewMid addSubview:self.participant];
        
        /** 需要从网上取得数据的label和ImageView */
        self.titleLabel = [[UILabel alloc] init];
//        [self.contentView addSubview:self.titleLabel];
        [self.backGroundImageViewBottom addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.timeLabel = [[UILabel alloc] init];
        [self.backGroundImageViewMid addSubview:self.timeLabel];
        [_timeLabel release];
        
        self.addressLabel = [[UILabel alloc] init];
        [self.backGroundImageViewMid addSubview:self.addressLabel];
        [_addressLabel release];
        
        self.category_nameLabel = [[UILabel alloc] init];
        [self.backGroundImageViewMid addSubview:self.category_nameLabel];
        [_category_nameLabel release];
        
        self.wisher_countLabel = [[UILabel alloc] init];
        [self.backGroundImageViewMid addSubview:self.wisher_countLabel];
        [_wisher_countLabel release];
        
        self.participant_countLabel = [[UILabel alloc] init];
        [self.backGroundImageViewMid addSubview:self.participant_countLabel];
        [_participant_countLabel release];
        
        self.activityListImageView = [[UIImageView alloc] init];
        [self.backGroundImageViewMid addSubview:self.activityListImageView];
        [_activityListImageView release];
        
        
        
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
/**1*/
    self.backGroundImageViewBottom.frame = CGRectMake(0, 15, self.frame.size.width, self.frame.size.height - 30);
    
    self.titleLabel.text = self.activity.title;
    self.titleLabel.frame = CGRectMake(15, 0, self.frame.size.width - 30, 40);
    
    
/**2*/
    self.backGroundImageViewMid.frame = CGRectMake(2, 40, self.frame.size.width - 4, 150);
    
/**3*/
    self.timeImageView.frame = CGRectMake(10, 5, 25, 25);
    
/**4*/
    self.addressImageView.frame = CGRectMake(10, 35, 25, 25);
    
/**5*/
    self.categoryImageView.frame = CGRectMake(10, 65, 25, 25);

    /** 截取时间的字符串,然后拼接. */
//    NSLog(@"%@",self.activity.begin_time);
//    NSLog(@"%@",self.activity.end_time);
    NSString *beginTime = [self.activity.begin_time substringWithRange:NSMakeRange(5, 11)];
    NSString *endTime = [self.activity.end_time substringWithRange:NSMakeRange(5, 11)];
    
    
    
    
    self.timeLabel.text = [NSString stringWithFormat:@"%@ -- %@",beginTime,endTime];
    self.timeLabel.font = [UIFont systemFontOfSize:16.0];
    self.timeLabel.frame = CGRectMake(40, 5, 210, 25);
    
    
    self.addressLabel.text = self.activity.address;
    self.addressLabel.font = [UIFont systemFontOfSize:16.0];
    self.addressLabel.frame = CGRectMake(40, 35, 210, 25);
    
    
/**6*/
    self.categoryLabel.text = @"类型:";
    
    self.category_nameLabel.text = self.activity.category_name;
    self.category_nameLabel.font = [UIFont systemFontOfSize:16.0];
    self.category_nameLabel.frame = CGRectMake(90, 65, 210, 25);
    
    
/**7*/
    self.wisherLabel.text = @"感兴趣:";
    self.wisherLabel.font = [UIFont systemFontOfSize:15.0];
    
    self.wisher_countLabel.text = [NSString stringWithFormat:@"%@",self.activity.wisher_count];
    self.wisher_countLabel.textColor = [UIColor redColor];
    self.wisher_countLabel.frame = CGRectMake(80, 105, 50, 30);
    
    
/**8*/
    self.participant.text = @"参加:";
    self.participant.font = [UIFont systemFontOfSize:15.0];
    
    self.participant_countLabel.text = [NSString stringWithFormat:@"%@",self.activity.participant_count];
    self.participant_countLabel.textColor = [UIColor redColor];
    self.participant_countLabel.frame = CGRectMake(180, 105, 50, 30);
    
    
    
    NSURL *url = [NSURL URLWithString:self.activity.image];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:data];
    
    self.activityListImageView.image = image;
    self.activityListImageView.frame = CGRectMake(260, 5, self.backGroundImageViewMid.frame.size.width - 270, 140);
    
    
}



@end
